Skip to main content

CreateObjcDelegateWithContext

Type

handler

Summary

Create an Objective-C object with LCB implementations of methods of a protocol.

Syntax

CreateObjcDelegateWithContext(<pProtocol>,<pHandlerMapping>,<pContext>)

Description

Use the CreateObjcDelegateWithContext handler to create instances of Objective-C delegate classes with LCB implementations of protocol methods. Once created these can be set in the usual way on an instance of the appropriate class (by binding to -setDelegate:), typically so that callbacks triggered by user interaction with a widget can be handled in LCB.

If no context is required to be passed as a parameter to the callback, use CreateObjcDelegate.

Some protocols consist of purely optional methods. In this case the information about the protocol's methods are not available from the
objective-c runtime API. In this situation CreateObjcInformalDelegateWithContext should be used instead.

Parameters

NameTypeDescription

pProtocol

The name of the protocol

pHandlerMapping

A mapping from the protocol's selector names to LCB handlers

pContext

Any context required in the callback.

Examples

handler NumberOfItemsInMenuCallback(in pContext as String, in pMenu as ObjcId) returns CLong
-- pContext is the tag for this menu
return the number of elements in mMenuArray[pContext]
end handler

public handler GetNSMenuDelegate(in pMenuTag as String) returns ObjcObject
return CreateObjcDelegateWithContext("NSMenuDelegate", \
{ "numberOfItemsInMenu:": \
NumberOfItemsInMenuCallback }, \
pMenuTag)
end handler

handler: CreateObjcDelegate, CreateObjcInformalDelegate, CreateObjcInformalDelegateWithContext

Thank you for your feedback!

Was this page helpful?